package uit.nfcmenu.models;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHelper extends SQLiteOpenHelper {

	/** The is run before. */
	public static boolean isRunBefore = false;

	/** The context. */
	Context context;
	public DatabaseHelper(Context context) {
		super(context, DbDefines.DATABASE_NAME, null,
				DbDefines.DATABASE_VERSION);
		this.context = context;
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// Create all data tables
		if (!isRunBefore) {
			
			createItemTable(db);
			createMenuTable(db);
			createOrderTable(db);
			isRunBefore = true;
		}
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
	}
	
	private void createItemTable(SQLiteDatabase db) { 
		db.execSQL("CREATE TABLE " + DbDefines.ItemModel+ " ("
			+ DbDefines.TableItem.itemID+ " INTEGER,"
			+ DbDefines.TableItem.itemName+ " TEXT,"
			+ DbDefines.TableItem.menuID+ " INTEGER,"
			+ DbDefines.TableItem.imageLink+ " TEXT,"
			+ DbDefines.TableItem.description+ " TEXT,"
			+ DbDefines.TableItem.discount+ " INTEGER,"
			+"PRIMARY KEY ("+DbDefines.TableItem.itemID+"))");
	}
	private void createMenuTable(SQLiteDatabase db) { 
		db.execSQL("CREATE TABLE " + DbDefines.MenuModel+ " ("
			+ DbDefines.TableMenu.menuID+ " INTEGER,"
			+ DbDefines.TableMenu.menuName+ " TEXT,"
			+ DbDefines.TableMenu.subMenuID+ " INTEGER,"
			+ DbDefines.TableMenu.imageLink+ " TEXT,"
			+ DbDefines.TableMenu.description+ " TEXT,"
			+"PRIMARY KEY ("+DbDefines.TableMenu.menuID+"))");
	}
	private void createOrderTable(SQLiteDatabase db) { 
		String query = "CREATE TABLE " + DbDefines.OrderModel+ " ("
				+ DbDefines.TableOrder.orderID+ " INTEGER,"
				+ DbDefines.TableOrder.itemID+ " INTEGER,"
				+ DbDefines.TableOrder.status+ " TEXT,"
				+ DbDefines.TableOrder.tableNo+ " INTEGER,"
				+ DbDefines.TableOrder.orderTime+ " TEXT,"
				+ DbDefines.TableOrder.quantity+ " INTEGER,"
				+ DbDefines.TableOrder.description+ " TEXT,"
				+ DbDefines.TableOrder.comment+ " TEXT,"
				+"PRIMARY KEY ("+DbDefines.TableOrder.orderID+"))";
		db.execSQL(query);
	}
}

